package com.cnpinxi.result;



import com.cnpinxi.result.ReturnCode;
import com.cnpinxi.tool.json.JsonHandler;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class ResultObj {

    /**
     * 结果代码
     */

    public static final int CODE_SUCCESS = 1;
    public static final int CODE_FAIL = 0;
    /**
     * 反馈状态
     */

    private int code;

    /**
     * 反馈信息
     */
    private String msg;

    /**
     * 反馈数据
     */
    private Object data;



    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public ResultObj() {
        super();
        // TODO Auto-generated constructor stub
    }

    public ResultObj(ReturnCode code, Object data) {

        this.code = code.getCode();
        this.msg = code.getMsg();
        this.data = data;
    }

    public ResultObj(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public String toJson() {
        return JsonHandler.objectToJson(this);
    }



    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }
    
    public static void main(String[] args) {
    	List<Map> li = new ArrayList<Map>();
		Map map = new HashMap();
		map.put("asdf", 1234);
		map.put("55", 1234);
		map.put("tt", 1234);
		Map map1 = new HashMap();
		li.add(map);
		map1.put("list", li);
		System.out.println(new ResultObj(1, "成功", map1).toJson());
	}
}
